package com.forum.controller;

import com.forum.mapper.StudentInfoMapper;
import com.forum.mapper.TeacherInfoMapper;
import com.forum.result.Result;
import com.forum.service.StudentInfoService;
import com.forum.service.TeacherInfoService;
import com.forum.utils.JwtHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/login")
@CrossOrigin
public class LoginController {
    @Autowired
    private StudentInfoService studentInfoService;
    @Autowired
    private TeacherInfoService teacherInfoService;
    @GetMapping
    public Result isVerify(@RequestParam String username,@RequestParam String password,@RequestParam String identity){
        switch(identity){
            case "student":
                return studentInfoService.verify(username,password);
            case "teacher":
                return teacherInfoService.verify(username,password);
            case "admin":
                if(studentInfoService.verify(username,password).getCode()==200){
                    return studentInfoService.verify(username,password);
                }
                if(teacherInfoService.verify(username, password).getCode()==200)
                    return teacherInfoService.verify(username,password);
            default:
                 return Result.ok();
        }

    }
}
